<% content_for :page_head do %>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
  <link rel="stylesheet" href="http://tablesorter.com/themes/blue/style.css" />
  <script type="text/javascript" src="http://autobahn.tablesorter.com/jquery.tablesorter.min.js"></script>
  <script type="text/javascript" src="http://tablesorter.com/addons/pager/jquery.tablesorter.pager.js"></script>
  <script type="text/javascript" src="/of/yoxview/yoxview-init.js"></script>
<% end %>
<% content_for :ujs do %>
  $.noConflict();
  var pp = 0;
  (function($){
    $(document).ready(function() {
      $("#wiki_list_check_box_all").click(function(){
        if($(this).attr('checked') == 'checked')
        {
          jQuery.each($('[name="files[]"]'), function() {
            $(this).attr('checked', 'checked');
          });
        }
        else
        {
          jQuery.each($('[name="files[]"]'), function() {
            $(this).removeAttr('checked');
          });
        }
      });

      $(":submit[name='delete']").click(function(){
        if($(':checkbox[name="files[]"]:checked').length == 0){
        alert('<%= t('No selected items', :scope => [:wiki, :message]) %>');
          return false;
        }
      });

      $("table")
        .tablesorter({widthFixed:true, widgets:['zebra'], headers:{0:{sorter:false}, 5:{sorter:false}}})
        .tablesorterPager({container: $("#pager"), size:10, positionFixed:false});
      $(".yoxview").yoxview();
    });
  })(jQuery);
<% end %>

<h2><%= t('Files List', :scope => :wiki) %></h2>

<%= render :partial => "functions" %>
<hr/>

<%= t('Upload files', :scope => :wiki) %>:
<%= form_tag({:action => 'web_upload'}, :multipart => true) do %>
  <%# form_tag ({:project_id => @project.id, :id => @release.id, :action => 'web_upload'}, :multipart => true) do %>
  <% for i in 1..3 %>
    <%= file_field_tag("upload_file[]") %><br/>
  <% end %>
  <%= submit_tag t('Upload', :scope => :wiki) %>
  <%= submit_tag t('Reset', :scope => :wiki), :type => 'reset' %> 
<% end %>

<%= form_tag({:action => 'delete_files'}) do %>
  </div>
  <table class="tablesorter yoxview">
    <thead>
      <th style="width:15px"><input type="checkbox" id="wiki_list_check_box_all"></th>
      <th><%= t('File Name', :scope => :wiki) %></th>
      <th><%= t('File Size', :scope => :wiki) %></th>
      <th><%= t('Upload Date', :scope => :wiki) %></th>
      <th><%= t('Image Size', :scope => :wiki) %></th>
      <th><%= t('Image Preview', :scope => :wiki) %></th>
    </thead>
  <% @files.each do |f| -%>
    <tr>
      <td><%= check_box_tag "files[]", f[:name] %></td>
      <td><%= f[:name] %></td>
      <td><%= number_to_human_size(f[:size]) %></td>
      <td><%= tz_datetime(f[:mtime]) %></td>
      <td><%= f[:imagesize] %></td>
      <td>
        <% if f[:name].to_s =~ /\.(jpg|jpeg|gif|bmp|png|ico)$/ -%>
          <a href="<%= "/of/wiki_upload/#{params[:project_id]}/#{f[:name]}" %>">
            <img src="<%= "/of/wiki_upload/#{params[:project_id]}/small/#{f[:name]}" %>" />
          </a>
        <% end -%> 
      </td>
    </tr>
  <% end -%>
  </table>
  <%= render :partial => "pager" %>
  <%= submit_tag t('Delete', :scope => :wiki), :name => 'delete', :confirm => t('Are you sure?', :scope => [:wiki, :message]) %>
<% end %>

<hr/>
<%= render :partial => "functions" %>
